//
//  ZWBaseModel.m
//  WanEr
//
//  Created by 高文萍 on 15/12/16.
//  Copyright © 2015年 高文萍. All rights reserved.
//

#import "ZWBaseModel.h"

@implementation ZWBaseModel

- (instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        //kvc要重写初始化方法不然会crash
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
    
}
/**
 KVC纠错方法
 value 未找到 key对应的值
 key 字典中未找到key
 
 */
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    if ([key isEqualToString:@"id"]) {
        self.replaceId = value;
    }
}
#pragma mark  便利构造器方法创建对象
+ (instancetype)baseModelWith:(NSDictionary *)dic
{
    //多态方式进行对象创建
    id model = [[[self class]alloc]initWithDic:dic];
    return model;
}

+ (NSMutableArray *)baseModelByArr:(NSMutableArray *)dataArr arr:(NSMutableArray *)arr{
        arr = [NSMutableArray array];
    for (NSDictionary *tempDic in dataArr) {
        @autoreleasepool {
            
            id model = [[self class]baseModelWith:tempDic];
            [arr addObject:model];
        }
    }
    return arr;
}



@end
